#include<iostream>
#include<cstring>

using namespace std;
const int N = 2510, M = 6210 * 2;
int h[N], e[M], w[M], ne[M], idx;
int dis[N], q[N];
bool st[N];
int n, m, x, y;
void spfa()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[x] = 0;
	int hh = 0, tt = 0;
	q[0] = { x };
	st[x] = 1;
	while (hh <= tt) {
		int t = q[hh++];
		st[t] = 0;
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[t] + w[i]) {
				dis[j] = dis[t] + w[i];
				if (!st[j]) {
					st[j] = 1;
					q[++tt] = j;
				}
			}
		}
	}
 }

void add(int a, int b, int c)
{
	e[idx] = b;
	w[idx] = c;
	ne[idx] = h[a];
	h[a] = idx++;
}
int main()
{
	cin >> n >> m >> x >> y;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
		add(b, a, c);
	}
	spfa();
	cout << dis[y] << endl;
	return 0;
}